#include "Common.h"
//==================================================
NODE *g_PlaneHead;
NODE *g_PlaneEnd;
//==================================================
int g_PlaneSize = 16;
int g_AutoFire;
//==================================================
char g_PlaneIcon[3][3]={
	{' ','A',' '},
	{'A','I','A'},
	{'M','M','M'}};
//==================================================
VOID CALLBACK PlaneTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
	if(g_Pause || 0==g_Time || g_Die)
	{
		return;
	}

	PlaneMove();
	PlaneAutoFire();
	
	InvalidateRect(hWnd, NULL, false);
}
//==================================================
void PlaneDraw(HDC hdc)
{
	NODE *pTemp = g_PlaneHead;
	int i = 0;

	int nColor[3]={0x000000, 0x007f40, 0x00ff00};

	while(i<3)
	{
		if(pTemp->nLX != pTemp->nX)
		{
			RECT rl = {pTemp->nLX,pTemp->nLY+i*16,pTemp->nLX+48,pTemp->nLY+i*16+16};
			SetTextColor(hdc, 0xffffff);
			DrawText(hdc, pTemp->LText[i], 3, &rl, DT_CENTER);
		}
		
		i++;
	}

	i = 0;

	while(i<3)
	{
		RECT rt = {pTemp->nX,pTemp->nY+i*16,pTemp->nX+48,pTemp->nY+i*16+16};
		SetTextColor(hdc, nColor[i]);
		DrawText(hdc, pTemp->Text[i], 3, &rt, DT_CENTER);

		i++;
	}
}
//==================================================
void PlaneCreate()
{
	if(NULL != g_PlaneHead)
	{
		return;
	}

	ListCreate(&g_PlaneHead, &g_PlaneEnd, g_PlaneIcon);
	g_PlaneHead->nDir = DIR_NULL;
	g_PlaneHead->nX = 504;
	g_PlaneHead->nY = 624 - 48;
	g_PlaneHead->nLX = 512;
	g_PlaneHead->nLY = 624 - 48;
}
//==================================================
void PlaneClear()
{
	if(NULL == g_PlaneHead)
	{
		return;
	}

	ListClear(&g_PlaneHead, &g_PlaneEnd);
}
//==================================================
void PlaneMove()
{
	if(NULL == g_PlaneHead)
	{
		return;
	}

	NODE *pTemp = g_PlaneHead;

	if(DIR_LEFT == pTemp->nDir && g_PlaneHead->nX > 0)
	{
		SaveLastStatus(pTemp);
		pTemp->nX = pTemp->nX - g_PlaneSize;
	}
	if(DIR_RIGHT == pTemp->nDir && pTemp->nX < 1056 - g_PlaneSize*3)
	{
		SaveLastStatus(pTemp);
		pTemp->nX = pTemp->nX + g_PlaneSize;
	}
}
//==================================================
void PlaneAutoFire()
{
	if(g_AutoFire || g_Fire)
	{
		BulletCreate();
	}
}
